from zope.interface import implements, Interface

from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from plone.memoize.instance import memoize

from my315ok.fangcan import fangcanMessageFactory as _


class IbrokerView(Interface):
    """
    broker view interface
    """

    def test():
        """ test method"""


class brokerView(BrowserView):
    """
    broker browser view
    """
    implements(IbrokerView)

    def __init__(self, context, request):
        self.context = context
        self.request = request

    @property
    def portal_catalog(self):
        return getToolByName(self.context, 'portal_catalog')

    @property
    def portal(self):
        return getToolByName(self.context, 'portal_url').getPortalObject()

    @memoize
    def photo(self):
        """fetch broker photo"""
        
        alt = self.context.Title()
        sc = self.context.absolute_url() + '/image'
        html='<img src="%s" alt="%s" />' % (sc,alt)
        return html
